<template>
	<view class="icons" @click.stop="likeTap">
		<uni-icons size="20" color="#f07373" :type="islike? 'heart-filled' : 'heart'"></uni-icons>
	</view>
</template>

<script>
	export default {
		props:{
			item:{
				type:Object,
				default(){
					return {}
				}
			}
		},
		data() {
			return {
				islike:false
			};
		},
		watch: {
			itemitem(newValue, oldValue) {
				this.islike=this.item.is_like
			}
		 },
		 created() {
		 	this.islike=this.item.is_like
		 },
		methods:{
			likeTap(){
				this.islike=!this.islike
				this.setUpdateLikes()
			},
			setUpdateLikes(){
				uni.showLoading()
				this.$api.update_like({
					 
					article_id:this.item._id
				}).then((res)=>{
					uni.hideLoading()
					uni.showToast({
						title:this.islike?"收藏成功":"取消收藏",
						icon:"none"
					})
				}).catch(()=>{
					uni.hideLoading()
				})
			}
		}
	}
</script>

<style lang="scss">
	.icons {
		position: absolute; //绝对定位；相对于父元素或者body进行定位
		top: 0;
		right: 0;
		display: flex;
		justify-content: center;
		align-items: center;
		width: 20px;
		height: 20px;
	}
</style>
